<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    html, body {
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
  <canvas id="cvs"></canvas>
  <script>
    let canvas = document.getElementById("cvs");
    let cxt = canvas.getContext("2d");
    let w = canvas.width = document.body.clientWidth;
    let h = canvas.height = document.body.clientHeight;
    let num = 8;
    let randin = Math.PI * 2 / num;
    let scale = 0;

    // 坐标原点为宽度和高度的一半
    cxt.translate(w / 2, h / 2);


    (function draw(cxt, number) {
      scale++;
      // 循环画出多种颜色花朵
      for (let i = 1; i <= number; i++) {
        let r = Math.random() + 0.2;
        drawFlower(cxt, num, {
          randin,
          x: 0, y: 0,
          y1: parseInt(w / 3 / i * r), 
          y2: parseInt(w / 3 / i * r),
          scale
        });
      }
    })(cxt, 6);


    function drawFlower(cxt, num, coor) {
      cxt.fillStyle = randomColor();
      cxt.beginPath();
      cxt.rotate(coor.randin + coor.scale);
      for (let i = 0; i < num; i++) {
        cxt.beginPath();
        cxt.moveTo(coor.x, coor.y);
        cxt.bezierCurveTo(
          Math.sin(coor.randin * i) * coor.y1, 
          Math.cos(coor.randin * i) * (-coor.y1), 
          Math.sin(coor.randin * (i + 1)) * coor.y2,
          Math.cos(coor.randin * (i + 1)) * (-coor.y2),
          coor.x,
          coor.y
        );
        cxt.stroke();
        cxt.fill();
      }
    }

    function randomColor() {
      let r = parseInt(Math.random() * 255);
      let g = parseInt(Math.random() * 255);
      let b = parseInt(Math.random() * 255);
      return `rgba(${r}, ${g}, ${b}, 0.5)`
    }
  </script>
</body>
</html>